Find Area of a Rectangle

Theory:

The area of a rectangle is calculated by multiplying its length by its width.

Python Code:

def calculate_rectangle_area(length, width):
    return length * width

# Taking input for the length and width of the rectangle and calculating its area
def calculate_and_display_rectangle_area():
    length = float(input("Enter the length of the rectangle: "))
    width = float(input("Enter the width of the rectangle: "))
    area = calculate_rectangle_area(length, width)
    print("Area of the rectangle:", area)

calculate_and_display_rectangle_area()

Example Output 1:

Enter the length of the rectangle: 5

Enter the width of the rectangle: 3

Area of the rectangle: 15.0

Example Output 2:

Enter the length of the rectangle: 7.5

Enter the width of the rectangle: 4.2

Area of the rectangle: 31.5

Code Explanation:

The function calculate_rectangle_area(length, width) calculates the area of a rectangle by multiplying its length by its width.

The function calculate_and_display_rectangle_area() takes input for the length and width of the rectangle, calculates its area using the aforementioned function, and displays the result.